#ifndef motor_h
#define motor_h

#include "Arduino.h"

/*
motor implements a motor interface with the Toshiba TB6612FNG
dual DC motor controller chip.  (Available on a SparkFun breakout
p/n ROB-09457)

The class methods allow the motor to be commanded with a +/- 255
integer command, determining the IN1 and IN2 outputs to the chip as
appropriate for CW and CCW operation of the motor.

The class offsets the motor command with friction and backlash bias
terms.  Friction bias is added to the output command in the direction of
the motor command.  Backlash bias is a constant bias added to the motor
command; equal and opposite biases on a pair of motors can be used to pre-
load a power train to eliminate backlash.
*/

class motor
{
  public:
    motor(void);
    void begin(int sby, int in1, int in2, int pwm);  // (IN1pin, IN2pin, PWMpin)
    void begin(int sby, int in1, int in2, int pwm, int f_off);  // ( " + friction bias)
    void begin(int sby, int in1, int in2, int pwm, int f_off, int b_off); // ( " + backlash bias)
    void command(int cmd);  // cmd is signed PWM command, constrained to -255 <= cmd <= 255

    int SBYpin;     // Standby pin
    int IN1pin;     // IN1 pin
    int IN2pin;     // IN2 pin
    int PWMpin;     // PWM pin - Note, must be PWM capable 
                    //           (3,5,6,9,10,11 on -168 & -328, 2 - 13 on Mega & Due)
    int f_bias;     // friction bias
    int b_bias;     // backlash bias

  private:
    boolean _init;

};

#endif
